package com.job;

import org.quartz.*;

/**
 * @author HuangSuip
 */
public abstract class BaseJob implements Job {

    public abstract String getCronExpression();

    public abstract String getGroupName();

    public abstract String getJobName();

    public Trigger getTrigger() {
        String cron = getCronExpression();
        if (cron == null || cron.trim().length() == 0) {
            throw new NullPointerException("null");
        }
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(getCronExpression());
        return TriggerBuilder.newTrigger().withIdentity(getJobName(), getGroupName()).withSchedule(scheduleBuilder).forJob(getJobDetail()).build();
    }

    public JobDetail getJobDetail() {
        return JobBuilder.newJob(this.getClass()).withIdentity(getJobName(), getGroupName()).storeDurably(true).requestRecovery(true).build();
    }
}
